//
//  RegisterAndForgetView.m
//  CCJD
//
//  Created by foreveross－bj on 14/12/20.
//  Copyright (c) 2014年 foreveross－bj. All rights reserved.
//

#import "RegisterAndForgetView.h"

@interface RegisterAndForgetView ()

@property (nonatomic, strong) UILabel *getCodeLabel;    //点击获取验证码label
@property (nonatomic, strong) UILabel *requestLabel;    //点击注册或修改密码

@end
@implementation RegisterAndForgetView
- (id)initWithFrame:(CGRect)frame requestName:(NSString *)requestName{
    self = [super initWithFrame:frame];
    if (self) {
        CGRect rect = frame;
        rect.size.height = kPTHeight * 3 + kIHeight * 2 + kTISpace * 3 + kITSpace * 2 + kTBSpace + kLHeight;
        self.frame = rect;
        [self initView];
        _requestLabel.text = requestName;
    }
    return self;
}
//初始化子视图
- (void)initView{
    //添加手机号输入框
    _phoneTextField = [[CustomTextField alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, kPTHeight)];
    _phoneTextField.placeholder = @"请输入手机号";
    _phoneTextField.leftViewMode = UITextFieldViewModeAlways;
    UIImageView * phoneImageVIew= [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kTIHeight, kTIHeight)];
    phoneImageVIew.image = [UIImage imageNamed:@"phone"];
    _phoneTextField.leftView = phoneImageVIew;
    _phoneTextField.textColor = [UIColor whiteColor];
    [self addSubview:_phoneTextField];
    
    //添加手机号输入框下划线
    UIImageView *phoneUnderImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, kPTHeight + kTISpace, self.frame.size.width, kIHeight)];
    phoneUnderImageView.backgroundColor = [UIColor whiteColor];
    [self addSubview:phoneUnderImageView];
    
    
    //添加验证码输入框
    _securityCodeTextField = [[CustomTextField alloc] initWithFrame:CGRectMake(0, kPTHeight + kTISpace + kIHeight + kITSpace, self.frame.size.width - kCLWidth, kPTHeight)];
    _securityCodeTextField.placeholder = @"请输入验证码";
    _securityCodeTextField.leftViewMode = UITextFieldViewModeAlways;
    UIImageView *securityCodeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kTIHeight, kTIHeight)];
    securityCodeImageView.image = [UIImage imageNamed:@"code"];
    _securityCodeTextField.leftView = securityCodeImageView;
    _securityCodeTextField.textColor = [UIColor whiteColor];
    [self addSubview:_securityCodeTextField];
    
    //添加获取验证码按钮
    _getCodeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width -  kCLWidth, kPTHeight + kTISpace + kIHeight + kITSpace, kCLWidth, kCLHeight)];
    _getCodeLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    _getCodeLabel.text = @"点击获取";
    _getCodeLabel.textColor = [UIColor whiteColor];
    _getCodeLabel.textAlignment = NSTextAlignmentCenter;
    UITapGestureRecognizer *codeTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getCode:)];
    [_getCodeLabel addGestureRecognizer:codeTapGesture];
    _getCodeLabel.userInteractionEnabled = YES;
    [self addSubview:_getCodeLabel];
    
    //添加验证码输入框下划线
    UIImageView *securityCodeUnderImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, kPTHeight * 2 + kTISpace * 2 + kIHeight + kITSpace, self.frame.size.width, kIHeight)];
    securityCodeUnderImageView.backgroundColor= [UIColor whiteColor];
    [self addSubview:securityCodeUnderImageView];
    
    
    //添加密码输入框
    _passwordTextField = [[CustomTextField alloc] initWithFrame:CGRectMake(0, kPTHeight * 2 + kIHeight * 2 + kTISpace * 2 + kITSpace * 2, self.frame.size.width, kPTHeight)];
    _passwordTextField.placeholder = @"请输入密码";
    _passwordTextField.leftViewMode = UITextFieldViewModeAlways;
    UIImageView *passwordImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kTIHeight, kTIHeight)];
    passwordImageView.image = [UIImage imageNamed:@"lock"];
    _passwordTextField.leftView = passwordImageView;
    _passwordTextField.textColor = [UIColor whiteColor];
    _passwordTextField.secureTextEntry = YES;
    [self addSubview:_passwordTextField];
    
    //添加密码输入框下划线
    UIImageView *passwordUnderImageVIew = [[UIImageView alloc] initWithFrame:CGRectMake(0, kPTHeight * 3 + kIHeight * 2 + kTISpace * 3 + kITSpace * 2, self.frame.size.width, kIHeight)];
    passwordUnderImageVIew.backgroundColor = [UIColor whiteColor];
    [self addSubview:passwordUnderImageVIew];
    
    
    //添加登录按钮
    self.requestLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.frame.size.width - kLWidth) / 2, kPTHeight * 3 + kIHeight * 2 + kTISpace * 3 + kITSpace * 2 + kTBSpace, kLWidth, kLHeight)];
    self.requestLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    _requestLabel.text = @"登录";
    _requestLabel.textAlignment = NSTextAlignmentCenter;
    _requestLabel.font = [UIFont systemFontOfSize:20];
    _requestLabel.textColor = [UIColor whiteColor];
    UITapGestureRecognizer *requestTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doRequest:)];
    [_requestLabel addGestureRecognizer:requestTap];
    _requestLabel.userInteractionEnabled = YES;
    [self addSubview:_requestLabel];
    
}


/**
 * 点击获取验证码后调用此方法。
 * @param tapGesture
 **/
- (void)getCode:(UITapGestureRecognizer *)tapGesture{
    if (_getCode) {
        _getCode();
    }
}
/**
 * 点击注册或修改密码按钮调用此方法。
 * @param tapGesture
 **/
- (void)doRequest:(UITapGestureRecognizer *)tapGesture{
    if (_forgetPassword) {
        _forgetPassword(_phoneTextField.text, _securityCodeTextField.text, _passwordTextField.text);
    }
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
